global replica_dir=	"<add path to your working directory>"

global data_dir=	"$replica_dir/data"
global output_dir=	"$replica_dir/output"

use "$data_dir/panel_simce4b6_sned_studlvl.dta", clear

 

/*----------------------------------------------------------------------------*/

**# Figure A.3: Student baseline variables' discontinuity plots, Grade 6 cohorts

/*----------------------------------------------------------------------------*/


global indepvars "mate_pre lect_pre nat_pre sch_municip_pre rural_rbd sch_stno_pre tipo_est_num_1 tipo_est_num_2 mom_edu_pre dad_edu_pre pad_inc_pre sch_gse_pre "  


collapse (mean) ${indepvars} (firstnm) st_ind25 st_ind10  sned_yr_* hg_* , by(rbd sned_yr)

la var st_ind25 "100% vs. 60%"
la var st_ind10 "60% vs. none"
 
la var st_ind25 "100% vs. 60%"
la var st_ind10 "60% vs. none"
 
la var nat_pre  	"Grade 4 Natural Science Score"
la var mate_pre 	"Grade 4 Math Score"
la var lect_pre 	"Grade 4 Reading Score"

la var sch_municip_pre 	"Municipal school"
la var rural_rbd 		"School rural location" 
la var sch_stno_pre 	"School enrolment"
la var tipo_est_num_1 	"School type, primary, grades 1-8"
la var tipo_est_num_2 	"School type, primary and secondary, grades 1-12"
la var sch_gse_pre 		"School socio-economic status"

la var mom_edu_pre 		"Education years, mother"
la var dad_edu_pre 		"Education years, father"
la var pad_inc_pre 		"Parental income, intervals"



/*----------------------------------------------------------------------------*/


global indepvars "mate_pre lect_pre nat_pre sch_municip_pre rural_rbd sch_stno_pre tipo_est_num_1 tipo_est_num_2 mom_edu_pre dad_edu_pre pad_inc_pre sch_gse_pre"  


foreach i in  25{
local label_st_ind`i': variable label st_ind`i'

	foreach y of global indepvars{

	local label_`y': variable label `y'
	
	rdplot `y' st_ind`i'  if abs(st_ind`i')<=1.5, h(1.5) ///
	graph_options(legend(off) graphregion(color(white)) ///
	xtitle("SNED index centered at zero") ///
	title("`label_`y'', 100% vs. 60%") )   ///
	xlab(-1.5(0.5)1.5)  binselect(esmv)  kernel(uni) p(2) masspoints(off)
	
	graph export "$output_dir/graph_6b4_`y'_`i'.png" , as(png) replace

	}
}


foreach i in  10{
local label_st_ind`i': variable label st_ind`i'

	foreach y of global indepvars{

	local label_`y': variable label `y'
	
	rdplot `y' st_ind`i'  if abs(st_ind`i')<=1.5, h(1.5) ///
	graph_options(legend(off) graphregion(color(white)) ///
	xtitle("SNED index centered at zero") ///
	title("`label_`y'', 60% vs. none") )   ///
	xlab(-1.5(0.5)1.5)  binselect(esmv)  kernel(uni) p(2) masspoints(off)
	
	graph export "$output_dir/graph_6b4_`y'_`i'.png" , as(png) replace

	}
}

